﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Microsoft.Practices.EnterpriseLibrary.Validation.Configuration;

namespace ElValWeb.ValidatorClientAdapters {
    public class ContainsCharactersValidatorClientAdapter : BaseClientAdapter<ContainsCharactersValidatorData> {
        public ContainsCharactersValidatorClientAdapter(ContainsCharactersValidatorData validatorData)
            : base(validatorData) {
            
        }

        public override IEnumerable<ModelClientValidationRule> GetClientRules(Type ownerType) {
            var rule = new ModelClientValidationRule {
                                                           ErrorMessage = ValidatorData.GetMessageTemplate(),
                                                           ValidationType = "containsCharactersValidator"
                                                       };
            rule.ValidationParameters["characters"] = ValidatorData.CharacterSet;
            rule.ValidationParameters["containsCharecters"] = ValidatorData.ContainsCharacters.ToString();

            return new[] {Negate(rule, ValidatorData.Negated) };

        }
    }
}
